/*
 *******************************************************************************
 *
 * Copyright (C) 2019-2020 Dialog Semiconductor.
 * This computer program includes Confidential, Proprietary Information
 * of Dialog Semiconductor. All Rights Reserved.
 *
 *******************************************************************************
 */

package com.dialog.suotalib.suota;

public class HeaderInfo69x extends HeaderInfo {

    /*
    typedef struct {
        uint8_t image_identifier[2];
        uint32_t size;
        uint32_t crc;
        uint8_t version_string[16];
        uint32_t timestamp;
        uint32_t pointer_to_ivt;
    } __attribute__((packed)) suota_1_1_image_header_da1469x_t;

    #define SUOTA_1_1_IMAGE_DA1469x_HEADER_SIGNATURE_B1       0x51
    #define SUOTA_1_1_IMAGE_DA1469x_HEADER_SIGNATURE_B2       0x71
    */

    public static final String TYPE = "69x";
    public static final int SIGNATURE = 0x5171;
    public static final int HEADER_SIZE = 34;

    private static final int OFFSET_PAYLOAD_SIZE = 2;
    private static final int OFFSET_PAYLOAD_CRC = 6;
    private static final int OFFSET_VERSION = 10;
    private static final int VERSION_LENGTH = 16;
    private static final int OFFSET_TIMESTAMP = 26;
    private static final int OFFSET_POINTER_TO_IVT = 30;

    private long pointerToIvt;

    public HeaderInfo69x(byte[] header, long totalBytes) {
        super(header, totalBytes);
    }

    public HeaderInfo69x(byte[] raw) {
        super(raw);
    }

    @Override
    protected void initializeTypeSpecific() {
        pointerToIvt = buffer.getInt(OFFSET_POINTER_TO_IVT) & 0xffffffffL;
    }

    @Override
    public String getType() {
        return TYPE;
    }

    @Override
    public int getSignature() {
        return SIGNATURE;
    }

    @Override
    public int getHeaderSize() {
        return HEADER_SIZE;
    }

    @Override
    protected int getOffsetPayloadSize() {
        return OFFSET_PAYLOAD_SIZE;
    }

    @Override
    protected int getOffsetPayloadCrc() {
        return OFFSET_PAYLOAD_CRC;
    }

    @Override
    protected int getOffsetVersion() {
        return OFFSET_VERSION;
    }

    @Override
    protected int getVersionLength() {
        return VERSION_LENGTH;
    }

    @Override
    protected int getOffsetTimestamp() {
        return OFFSET_TIMESTAMP;
    }

    @Override
    public long getPayloadOffset() {
        return pointerToIvt;
    }

    public long getPointerToIvt() {
        return pointerToIvt;
    }
}
